package com.blogzhxs.utils;

import com.blogzhxs.model.BOMFile;

import java.io.File;
import java.util.Scanner;

/**
 * Created by 醉花阴柳 on 2016/12/9.
 */
public class RemoveBOMHead {

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.print("请输入文件或目录: ");
        String path = input.nextLine();
        File file = new File(path);
        if(file.isDirectory()){
            if(deepRemove(file)){
                System.out.println("移除BOM成功");
            }else{
                System.out.println("移除BOM失败");
            }
        }else{
            BOMFile bomFile = new BOMFile(file);
            if(bomFile.removeBOM()){
                System.out.println("移除BOM成功");
            }else{
                System.out.println("移除BOM失败");
            }
        }
    }

    public static boolean deepRemove(File file){
        File[] files = file.listFiles();
        if(files != null) {
            for (File f : files) {
                if (f.isDirectory()) {
                    deepRemove(f);
                } else {
                    BOMFile bomFile = new BOMFile(f);
                    bomFile.removeBOM();
                }
            }
        }
        return true;
    }

}
